package com.ruoyi.demo.controller.User;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.demo.domain.UserRepair;
import com.ruoyi.demo.service.IUserRepairService;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 我的报修信息管理
 * @author asus
 */
@RestController
@RequestMapping("/demo/myRepair")
public class MyRepairController extends BaseController {
    
    @Autowired
    private IUserRepairService userRepairService;

    /**
     * 查询用户报修列表
     */
    @GetMapping("/list/{userId}")
    public TableDataInfo list(@PathVariable("userId") Long userId, UserRepair repair) {
        startPage();
        repair.setUserId(userId);
        System.out.println("查询参数: " + repair.toString());
        List<UserRepair> list = userRepairService.selectRepairListByUserId(repair);
        return getDataTable(list);
    }

    /**
     * 获取用户报修详细信息
     */
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId) {
        return success(userRepairService.selectRepairByRepairId(repairId));
    }

    /**
     * 新增报修
     */
    @PostMapping
    public AjaxResult add(@RequestBody UserRepair repair) {
        return toAjax(userRepairService.insertRepair(repair));
    }

    /**
     * 修改报修
     */
    @PutMapping
    public AjaxResult edit(@RequestBody UserRepair repair) {
        return toAjax(userRepairService.updateRepair(repair));
    }

    /**
     * 删除报修
     */
    @DeleteMapping("/{repairIds}")
    public AjaxResult remove(@PathVariable Long[] repairIds) {
        return toAjax(userRepairService.deleteRepairByRepairIds(repairIds));
    }
} 